<template>
  <div class="forum-item">
    <div class="item" @click="toLinkFun">
      <div class="item-top">
        <div class="item-tip" v-if="item.is_top == 1">置顶</div>
        <div class="item-top-title u-line-1">
          {{ item.title }}
        </div>
        <div class="item-user" v-if="item.user_info">
          <div class="item-user-logo">
            <img v-if="item.user_info.image" :src="item.user_info.image" alt="" />
            <img v-else src="@/assets/img/touxiang.png" alt="" />
          </div>
          <div class="item-user-content">
            <div class="item-user-name">{{ item.user_info.name }}</div>
            <div class="item-user-desc">
              {{ item.user_info.bm_title }} {{ item.user_info.profession }}
            </div>
          </div>
        </div>
      </div>
      <div class="item-content">
        <div class="item-content-img" v-if="item.thumb">
          <img :src="item.thumb" alt="" />
        </div>
        <div class="item-content-right">
          <div class="item-content-desc u-line-3">
            {{ item.description }}
          </div>
          <div class="item-content-footer">
            <div class="item-content-action">
              <div class="item-content-footer-left">
                <span>{{ item.type_title }} · </span>
                <span style="color: #9fa6c2">{{ item.created_at }}</span>
              </div>
              <div class="item-content-footer-right">
                <div class="item-content-icon" @click.stop="commentFun(item)">
                  <img src="@/assets/img/icon-pinglun.png" alt="" />
                  <span>评论</span>
                  <span style="color: #9fa6c2">({{ item.comment_num }})</span>
                </div>
                <div class="item-content-icon" @click.stop="zanFun()">
                  <img
                    v-if="item.is_like == 1"
                    src="@/assets/img/icon-dianzan2.png"
                    alt=""
                  />
                  <img v-else src="@/assets/img/icon-dianzan.png" alt="" />
                  <span>点赞</span>
                  <span style="color: #9fa6c2">({{ item.like_num }})</span>
                </div>
              </div>
            </div>
            <div class="item-content-comment" v-if="item.best">
              <div class="item-content-comment--tip">最佳评论</div>
              <div class="item-content-comment--title u-line-1">
                <span style="color: #4f8af8">{{ item.best.c_user_name }}：</span>
                <span>{{ item.best.content }}</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>


export default {
  name: "ForumItem",
  props: {
    item: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  methods: {
    commentFun(item) {
      this.$emit("comment", item);
    },
    zanFun() {
      this.$emit("zan", this.item);
    },
    toLinkFun() {
      this.$router.push({
        path: `/forum-detail/${this.item.id}`,
      });
    },
  },
};
</script>

<style lang="less" scoped>
.forum-item {
  width: 100%;

  .item {
    width: 100%;
    background: rgba(#64aefb, 0.1);
    border-radius: 0.0625rem;
    margin-bottom: 0.375rem;
    padding-bottom: 0.025rem;
    cursor: pointer;

    .item-top {
      display: flex;
      align-items: center;
      padding: 0 0.475rem;
      height: 0.8rem;
      box-sizing: border-box;

      .item-tip {
        width: 0.6rem;
        height: 0.3rem;
        text-align: center;
        line-height: 0.3rem;
        background: #f18c3c;
        border-radius: 0.025rem;
        font-size: 0.15rem;
        color: #ffffd2;
        margin-right: 0.25rem;
      }

      .item-top-title {
        font-size: 0.25rem;
        color: #000;
        font-weight: bold;
        width: 11.25rem;
      }

      .item-user {
        display: flex;
        align-items: center;
        flex: 1;
        justify-content: flex-end;

        .item-user-logo {
          width: 0.55rem;
          height: 0.55rem;
          margin-right: 0.2rem;

          img {
            width: 100%;
            height: 100%;
            border-radius: 50%;
          }
        }

        .item-user-name {
          font-size: 0.2rem;
          color: #4f8af8;
          font-weight: bold;
        }

        .item-user-desc {
          font-size: 0.125rem;
          color: #666;
          padding-top: 0.05rem;
        }
      }
    }

    .item-content {
      display: flex;
      box-sizing: border-box;
      padding: 0.45rem;
      margin: 0 0.025rem;
      background: #fff;

      .item-content-img {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 3.2875rem;
        height: 1.8875rem;
        margin-right: 0.4375rem;

        img {
          width: 100%;
          height: 100%;
          object-fit: cover;
        }
      }

      .item-content-right {
        position: relative;
        height: 1.8875rem;
        flex: 1;
      }

      .item-content-footer {
        position: absolute;
        left: 0;
        bottom: 0;
        width: 100%;

        .item-content-action {
          display: flex;
          align-items: center;
          justify-content: space-between;
        }

        .item-content-comment {
          display: flex;
          align-items: center;
          padding-top: 0.1625rem;
          font-size: 0.2rem;
          color: #333;

          .item-content-comment--tip {
            text-align: center;
            line-height: 0.3rem;
            width: 0.9rem;
            height: 0.3rem;
            background: #f18c3c;
            border-radius: 0.025rem;
            font-size: 0.15rem;
            color: #ffffd2;
            margin-right: 0.1875rem;
          }
        }

        .item-content-footer-left {
          font-size: 0.2rem;
          color: #000;
        }

        .item-content-footer-right {
          display: flex;
          align-items: center;

          .item-content-icon {
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 0.2rem;
            color: #000;
            margin-left: 0.4rem;
            cursor: pointer;
            user-select: none;

            span {
              margin-right: 0.1rem;
            }

            img {
              width: 0.2rem;
              height: 0.2rem;
              margin-right: 0.05rem;
            }
          }
        }
      }

      .item-content-desc {
        font-size: 0.2rem;
        color: #000;
        line-height: 0.3rem;
      }
    }
  }
}
</style>
